<?php

namespace common\model;

use think\model\RelationModel;

class ReviewWorkflowModel extends RelationModel
{

    //自动验证
    protected $_validate = [
        ['name', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['name', '1,255', '', self::EXISTS_VALIDATE, 'length'],
        ['config', '', '', self::EXISTS_VALIDATE, 'array'],
    ];

    //自动完成
    protected $_auto = [
        ['uuid', 'create_uuid', self::MODEL_INSERT, 'function'],
        ['description', 'fill_text_default_val', self::MODEL_INSERT, 'function'],
        ['is_deleted', 'no', self::MODEL_INSERT, 'string'], //自动填充删除状态
        ['created', 'time', self::MODEL_INSERT, 'function'], //自动填充删除状态
        ['updated', 'time', self::MODEL_BOTH, 'function'],
        ['config', 'json_encode', self::EXISTS_VALIDATE, 'function'],

    ];

    /**
     * 获取器 获取配置
     * @param $value
     * @param $data
     * @return array|mixed
     */
    public function getConfigAttr($value, $data)
    {
        // 判断是否有值
        if (!empty($value)) {
            $jsonDictData = json_decode($value, true);
        } else {
            $jsonDictData = [];
        }
        return $jsonDictData;
    }
}
